Skip to content

cli: add Size column to \l+ and \dt+ #170978

Merged
trunk-io[bot] merged 2 commits into
cockroachdb:masterfrom
rafiss:metacommand-l-plus
May 28, 2026
Merged

cli: add Size column to \l+ and \dt+ #170978
trunk-io[bot] merged 2 commits into
cockroachdb:masterfrom
rafiss:metacommand-l-plus

Conversation

@rafiss

@rafiss rafiss commented May 27, 2026

Copy link
Copy Markdown
Collaborator

PG's psql shows database and per-table on-disk sizes in the verbose
variants of \l and \dt. CRDB's CLI carried explicit TODOs next to
those columns waiting for the pg_database_size and pg_table_size
builtins to exist. Now that both builtins (and pg_size_pretty) are
available, wire them up.

This makes the \l+ and \dt+ queries match Postgres exactly. The
sizes come from the periodically-refreshed system.table_metadata
cache and may lag the truth by minutes.

TestDescribe gains a seed of system.table_metadata so the goldens
exercise the real per-index lookup path. The details JSONB mirrors
what tableMetadataUpdater writes in production (replica_count +
primary_index_id + index_sizes), so we are not just relying on the
mixed-version replication_size_bytes fallback.

Resolves: #85834

Release note (cli change): The \l+ and \dt+ metacommands in the
built-in SQL shell now include a Size column showing on-disk byte
counts, matching PostgreSQL's psql. Database sizes come from
pg_database_size; table sizes come from pg_table_size. Values are
read from a periodically-refreshed internal cache
and may lag the live byte count by minutes.

@trunk-io

trunk-io Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor

😎 Merged successfully - details.

@blathers-crl

blathers-crl Bot commented May 27, 2026

Copy link
Copy Markdown

Your pull request contains more than 1000 changes. It is strongly encouraged to split big PRs into smaller chunks.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@cockroach-teamcity

Copy link
Copy Markdown
Member

This change is Reviewable

@rafiss rafiss changed the title tablemetadatacache: store per-index sizes in details cli: add Size column to \l+ and \dt+ May 27, 2026
@rafiss rafiss marked this pull request as ready for review May 28, 2026 14:44
@rafiss rafiss requested review from a team as code owners May 28, 2026 14:44
@rafiss rafiss requested review from dhartunian and spilchen and removed request for a team May 28, 2026 14:44
@rafiss rafiss force-pushed the metacommand-l-plus branch 2 times, most recently from 1d946b9 to 7f27a1a Compare May 28, 2026 16:16
rafiss and others added 2 commits May 28, 2026 14:34
PG's psql shows database and per-table on-disk sizes in the verbose
variants of \l and \dt. CRDB's CLI carried explicit TODOs next to
those columns waiting for the pg_database_size and pg_table_size
builtins to exist. Now that both builtins (and pg_size_pretty) are
available, wire them up.

This makes the \l+ and \dt+ queries match Postgres exactly. The
sizes come from the periodically-refreshed system.table_metadata
cache and may lag the truth by minutes.

TestDescribe gains a seed of system.table_metadata so the goldens
exercise the real per-index lookup path. The details JSONB mirrors
what tableMetadataUpdater writes in production (replica_count +
primary_index_id + index_sizes), so we are not just relying on the
mixed-version replication_size_bytes fallback.

Resolves: cockroachdb#85834

Release note (cli change): The \l+ and \dt+ metacommands in the
built-in SQL shell now include a Size column showing on-disk byte
counts, matching PostgreSQL's psql. Database sizes come from
pg_database_size; table sizes come from pg_table_size. Values are
read from a periodically-refreshed internal cache
and may lag the live byte count by minutes.
…k storage

Virtual tables (pg_catalog, information_schema, crdb_internal) and
physical tables whose system.table_metadata row hasn't been written
yet now return NULL from pg_relation_size, pg_table_size,
pg_total_relation_size, and pg_indexes_size, instead of 0. NULL is a
truer signal than "0 bytes" for relations that have no on-disk
concept, and it lets SUM-style aggregations skip those rows rather
than adding meaningless zeros.

Release note: None

Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
@rafiss rafiss force-pushed the metacommand-l-plus branch from 7f27a1a to 0d85193 Compare May 28, 2026 18:46

@spilchen spilchen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm: nice to resolve a long standing issue

@spilchen partially reviewed 1 file and made 1 comment.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on dhartunian).

@trunk-io trunk-io Bot merged commit 63642d9 into cockroachdb:master May 28, 2026
26 checks passed
@rafiss rafiss deleted the metacommand-l-plus branch May 29, 2026 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cli: support \l+ for table and database size

3 participants